//
//  EmployeeOrderDetailCell.m
//  ForestPack
//
//  Created by jimmy on 2018/7/23.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "EmployeeOrderDetailCell.h"
#import "Masonry.h"

@interface EmployeeOrderDetailCell()<UITextFieldDelegate>



@end

@implementation EmployeeOrderDetailCell

+(EmployeeOrderDetailCell *)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID = @"EmployeeOrderDetailCell";
    EmployeeOrderDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[EmployeeOrderDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
        [cell creatViewUI];
    }
    return cell;
}

-(void)sureClick
{
    //如果输入的有内容点击要跳转到下个界面
    
}

-(void)creatViewUI
{
    UILabel *nameLabel = [[UILabel alloc] init];
    nameLabel.text = @"设计费用：";
    nameLabel.textColor = FONTCOLOR_BLACK;
    nameLabel.textAlignment = NSTextAlignmentLeft;
    nameLabel.font = Kfont(14);
    [self addSubview:nameLabel];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(13);
        make.top.equalTo(self.mas_top).offset(15);
        make.width.equalTo(@80);
        make.height.equalTo(@20);
    }];
    
    UIView *leftView = [[UIView alloc] init];
    leftView.backgroundColor = [UIColor clearColor];
    [self addSubview:leftView];
    [leftView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(nameLabel.mas_right).offset(10);
        make.top.equalTo(self.mas_top).offset(10);
        make.width.equalTo(@15);
        make.height.equalTo(@30);
    }];
    UITextField *moneyTextF = [[UITextField alloc] init];
    moneyTextF.leftViewMode = UITextFieldViewModeAlways;
    moneyTextF.leftView = leftView;
    moneyTextF.delegate = self;
    moneyTextF.placeholder = @"请输入金额";
    moneyTextF.textColor = FONTCOLOR_BLACK;
    moneyTextF.textAlignment = NSTextAlignmentLeft;
    moneyTextF.keyboardType = UIKeyboardTypeNumberPad;
    moneyTextF.layer.masksToBounds = YES;
    moneyTextF.layer.cornerRadius = 15;
    moneyTextF.layer.borderWidth = 1;
    moneyTextF.layer.borderColor = RGB_COLOR(153, 153, 153).CGColor;
    moneyTextF.font = Kfont(14);
    [self addSubview:moneyTextF];
    [moneyTextF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(nameLabel.mas_right).offset(10);
        make.top.equalTo(self.mas_top).offset(10);
        make.width.equalTo(@100);
        make.height.equalTo(@30);
    }];
    //监听textfield的输入状态
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldDidChangeValue:) name:UITextFieldTextDidChangeNotification object:nil];
    
    UILabel *unitLabel = [[UILabel alloc] init];
    unitLabel.text = @"元";
    unitLabel.textColor = RGB_COLOR(237, 34, 59);
    unitLabel.textAlignment = NSTextAlignmentLeft;
    unitLabel.font = Kfont(14);
    [self addSubview:unitLabel];
    [unitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(moneyTextF.mas_right).offset(10);
        make.top.equalTo(self.mas_top).offset(15);
        make.width.equalTo(@30);
        make.height.equalTo(@20);
    }];
    
    self.sureBtn = [[OperateButton alloc] init];
    [self.sureBtn setTitle:@"确认议价" forState:UIControlStateNormal];
    [self.sureBtn addTarget:self action:@selector(sureClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.sureBtn];
    [self.sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(13);
        make.top.equalTo(moneyTextF.mas_bottom).offset(60);
        make.width.equalTo(@(SCREEN_WIDTH - 26));
        make.height.equalTo(@44);
    }];
    
    self.sureEmployeBtn = [[OperateButton alloc] init];
    [self.sureEmployeBtn setTitle:@"确认雇佣" forState:UIControlStateNormal];
    [self.sureEmployeBtn addTarget:self action:@selector(sureClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.sureEmployeBtn];
    [self.sureEmployeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(13);
        make.top.equalTo(moneyTextF.mas_bottom).offset(60);
        make.width.equalTo(@(SCREEN_WIDTH - 26));
        make.height.equalTo(@44);
    }];
    
    self.refuseBtn = [[OperateButton alloc] init];
    [self.refuseBtn setTitle:@"拒绝订单" forState:UIControlStateNormal];
    [self.refuseBtn addTarget:self action:@selector(sureClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.refuseBtn];
    [self.refuseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(13);
        make.top.equalTo(self.sureEmployeBtn.mas_bottom).offset(15);
        make.width.equalTo(@(SCREEN_WIDTH - 26));
        make.height.equalTo(@44);
    }];
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    
}

//这里可以通过发送object消息获取注册时指定的UITextField对象
- (void)textFieldDidChangeValue:(NSNotification *)notification
{
    UITextField *sender = (UITextField *)[notification object];
    if(sender.text.length != 0)
    {
        [self.sureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }else
    {
        [self.sureBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    }
}

//可以得到用户输入的字符
//-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
//{
//    return YES;
//}

//点击Return键的时候，（标志着编辑已经结束了）
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    return YES;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self endEditing:true];
}

@end
